package com.sali.design_pattern.c_factory_method_pattern.lesson_01;

import com.sali.design_pattern.c_factory_method_pattern.lesson_01.factory.IUserVIPFactory;
import com.sali.design_pattern.c_factory_method_pattern.lesson_01.factory.impl.NormalUserServiceFactory;
import com.sali.design_pattern.c_factory_method_pattern.lesson_01.service.IUserVipService;
import com.sali.design_pattern.c_factory_method_pattern.lesson_01.service.impl.NormalUserVipService;

/**
 * @description:
 * @date: 2023/11/18 15:36.
 * @version: 1.0
 */
public class Lesson01Starter {


    public static <T extends IUserVIPFactory> T createVip(Class<T> clz) {
        try {
            return (T) clz.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static <T extends IUserVipService> T getVipService(Class<T> clz) {
        try {
            return (T) clz.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {
        NormalUserServiceFactory normalUserServiceFactory = Lesson01Starter.createVip(NormalUserServiceFactory.class);
        IUserVipService normal01Service = normalUserServiceFactory.createVip();
        System.out.println(normal01Service.getUserInfo());

        NormalUserVipService normal02Service = Lesson01Starter.getVipService(NormalUserVipService.class);
        System.out.println(normal02Service.getUserInfo());
    }

}
